home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9228 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to copy an object?
  5. Date: 29 Feb 1996 14:20:43 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4h4cnr$kd@dawn.mmm.com>
  8. References: <4h05rb$su6@atlas.tncnet.com>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Simon Lee (SimonLee) wrote:
  13.  
  14. > Hello,
  15.  
  16. > I'm trying to have a member function return a duplicate copy of a
  17. > member data object.  How would I go about this?
  18.  
  19. > Ie.
  20.  
  21. > class x {
  22. > private:
  23. >     Y  *object_of_class_y;
  24.  
  25. > public:
  26. >     Y GetY();
  27. > };
  28.  
  29.  
  30. > I would like GetY() to return a copy of object_of_class_y, not a pointer
  31. > to it.
  32.  
  33. This should do it:
  34.  
  35.     Y x::GetY() { return *object_of_class_y; }
  36.  
  37. > Any email responses appreciated.
  38.  
  39. People read your article because it looked interesting.  They deserve
  40. to read the answers too.
  41. --
  42. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  43. 3M Company                      phone:  (612) 737-4643
  44. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  45. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  46.     But 3M speaks for me -- I did not write the following line:
  47.  
  48. Opinions expressed herein are my own and may not represent those of 3M.
  49.